const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');

function resolve(dir) {
    return path.join(__dirname, dir);
}

module.exports = {
    publicPath:process.env.NODE_ENV==='production'?'/mulan':'/',
    outputDir:'mulan',
    indexPath:'index.html',
    /* 开启vue运行时模板编译功能！！ */
    runtimeCompiler: true,
    css: {
        loaderOptions: {
            less: {
                javascriptEnabled: true,
            },
        },
    },
    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            return {
                plugins: [
                    new CopyWebpackPlugin([
                        {
                            from: 'node_modules/@aspnet/signalr/dist/browser/signalr.min.js',
                            to: 'lib',
                        },
                        {
                            from: 'node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.signalr-client.js',
                            to: 'lib',
                        },
                        {
                            from: 'src/lib/abp.js',
                            to: 'lib',
                        },
                    ]),
                ],
                devtool: 'source-map',
            };
        } else {
            return {
                plugins: [
                    new CopyWebpackPlugin([
                        {
                            from: 'node_modules/@aspnet/signalr/dist/browser/signalr.min.js',
                            to: 'lib',
                        },
                        {
                            from: 'node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.signalr-client.js',
                            to: 'lib',
                        },
                        {
                            from: 'src/lib/abp.js',
                            to: 'lib',
                        },
                    ]),
                ],
                devtool: 'source-map',
            };
        }


    },

    chainWebpack: config => {
        /* 配置svg图标自动加载 begin */
        config.module
            .rule('svg')
            .exclude.add(resolve('src/components/form/icons'))
            .end();
        config.module
            .rule('icons')
            .test(/\.svg$/)
            .include.add(resolve('src/components/form/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({
                symbolId: 'icon-[name]',
            });
        /* 配置svg图标自动加载 end */
    },
};
